package com.project.util.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * ClassName: redisUtil <br/>
 * Description: <br/>
 * date: 2019/1/7 8:34<br/>
 *
 * @author lenovo<br />
 * @since JDK 1.8
 */
@Component
public class RedisUtil {

    @Resource
    public  RedisTemplate redisTemplate;

    /**
     * 维护一个本类的静态变量
     */
    public static  RedisUtil redisUtil;

    /**
     * 初始化把本类redisTemplate 赋值给  静态本类变量
     */
    @PostConstruct
    public void init(){
        redisUtil = this;
        redisUtil.redisTemplate = this.redisTemplate;
    }


    /**
     * 通过维护的静态变量使用redisTemplate
     * @param name
     * @return
     */
    public static final Long size(String name){
        return  redisUtil.redisTemplate.opsForList().size(name);
    }

    public static  final  void right(String k,Object v){
        redisUtil.redisTemplate.opsForList().rightPush(k,v);
    }

}
